package com.semidata.rtd.core.log;

import java.io.File;

public class LogBlock {
	
	private static final int capacity = 4 * 1024 * 1024;
	
	private File path;
	
	private byte[] buffer;
	private int position;
	
	public LogBlock(File path) {
		this.path = path;
		this.buffer = new byte[capacity];
		this.position = 0;
	}
	
	public boolean write(String str) {
		if (position + str.length() > capacity)
			return false;
		System.arraycopy(str.getBytes(), 0, buffer, position, str.length());
		position += str.length();
		return true;
	}
	
	public byte[] getBytes() {
		return buffer;
	}
	
	public int size() {
		return position;
	}
	
	public File getPath() {
		return path;
	}

	public int getFreeSpace() {
		return capacity - position;
	}
}
